#include <iostream>

using namespace std;

int main()
{
	int n;
	int ret=0;
	cin>>n;
	int pre=0,now;
	while(n--)
	{
		cin>>now;
		if(now>pre)
		{
			ret+=now-pre;
		}
		pre=now;
	}
	cout<<ret<<endl;
	return 0;
}
